﻿@{
    const int maxpage = 5;
    var totalPage = (int)ViewBag.TotalPage;
    var currentPage = (int)ViewBag.CurrentPage;
    int pageIndex;
    int nextpage;
}
@Html.Hidden("totalPage",@totalPage)
@Html.Hidden("currentPage",@currentPage)
<section class="paging smallText">
    <section class="range"></section>
    <section class="page">
        <ul class="pageIndex">
            @if (totalPage > 1 && totalPage <= maxpage)
            {
                <li>Trang @currentPage / @totalPage</li>
                <li><a class="first" idx="1" href="#" onclick="firstPage(1, '@ViewBag.Url');" title="Trang đầu"></a></li>
                pageIndex = currentPage - 1;
                if (currentPage == 1)
                {
                    pageIndex = totalPage;
                }
                <li><a class="prev nofollow" idx="@pageIndex" href="#" title="Trang trước"></a></li>
                for (var i = 1; i <= totalPage; i++)
                {
                    var style = "";
                    if (i == currentPage)
                    {
                        style = "active";
                    }
                    <li><a class="@style" href="#" idx="@i" title="">@i</a></li>
                }
                nextpage = currentPage + 1;
                if (currentPage == totalPage)
                {
                    nextpage = 1;
                }
                <li><a class="next nofollow" href="#" idx="@nextpage" title="Trang tiếp"></a></li>
                <li><a class="last nofollow" href="#" idx="@totalPage" title="Trang cuối"></a></li>
            }
            else
            {
                if (totalPage == 1)
                {
                    <li>Trang @currentPage / @totalPage</li>
                    <li><a class="first nofollow" href="#" idx="1" title="Trang đầu">
                            <img alt="" class="firstImgEnable" src="/Content/themes/admin/images/clear.gif" /></a></li>
                    <li><a class="prev nofollow" href="#" idx="1" title="Trang trước">
                            <img alt="" class="prevImgEnable" src="/Content/themes/admin/images/clear.gif" /></a></li>
                    <li><a class="active" href="#" idx="1" title="">1</a></li>
                    <li><a class="next nofollow" href="#" idx="1" title="Trang tiếp">
                            <img alt="" class="nextImgEnable" src="/Content/themes/admin/images/clear.gif" /></a></li>
                    <li><a class="last nofollow" href="#" idx="1" title="Trang cuối">
                            <img alt="" class="lastImgEnable" src="/Content/themes/admin/images/clear.gif" /></a></li>
                }
                if (totalPage > 1 && totalPage > maxpage)
                {
                    string style;
                    if (currentPage <= 2)
                    {
                        <li>Trang @currentPage / @totalPage</li>
                        <li><a class="first nofollow" href="#" idx="1" title="Trang đầu">
                                <img alt="" class="firstImgEnable" src="/Content/themes/admin/images/clear.gif" /></a></li>
                        pageIndex = currentPage - 1;
                        if (currentPage == 1)
                        {
                            pageIndex = totalPage;
                        }
                        <li><a class="prev nofollow" href="#" idx="@pageIndex" title="Trang trước">
                                <img alt="" class="prevImgEnable" src="/Content/themes/admin/images/clear.gif" /></a></li>
                        for (var i = 1; i <= maxpage; i++)
                        {
                            style = "";
                            if (i == currentPage)
                            {
                                style = "active";
                            }
                            <li><a class="@style nofollow" href="#" idx="@i" title="">@i</a></li>
                        }
                        nextpage = currentPage + 1;
                        if (currentPage == totalPage)
                        {
                            nextpage = 1;
                        }
                        <li><a class="next nofollow" href="#" idx="@nextpage" title="Trang tiếp">
                                <img alt="" class="nextImgEnable" src="/Content/themes/admin/images/clear.gif" /></a></li>
                        <li><a class="last nofollow" href="#" idx="@totalPage" title="Trang cuối">
                                <img alt="" class="lastImgEnable" src="/Content/themes/admin/images/clear.gif" /></a></li>
                    }
                    else if (currentPage > 2 && currentPage < totalPage - 2)
                    {
                        <li>Trang @currentPage / @totalPage</li>
                        <li><a class="first nofollow" href="#" idx="1" title="Trang đầu">
                                <img alt="" class="firstImgEnable" src="/Content/themes/admin/images/clear.gif" /></a></li>
                        pageIndex = currentPage - 1;
                        if (currentPage == 1)
                        {
                            pageIndex = totalPage;
                        }
                        <li><a class="prev nofollow" href="#" idx="@pageIndex" title="Trang trước">
                                <img alt="" class="prevImgEnable" src="/Content/themes/admin/images/clear.gif" /></a></li>

                        for (var i = currentPage - 2; i <= currentPage + 2; i++)
                        {
                            style = "";
                            if (i == currentPage)
                            {
                                style = "active";
                            }
                            <li><a class="@style nofollow" href="#" idx="@i" title="">@i</a></li>
                        }
                        nextpage = currentPage + 1;
                        if (currentPage == totalPage)
                        {
                            nextpage = 1;
                        }
                        <li><a class="next nofollow" href="#" idx="@nextpage" title="Trang tiếp">
                                <img alt="" class="nextImgEnable" src="/Content/themes/admin/images/clear.gif" /></a></li>
                        <li><a class="last nofollow" href="#" idx="@totalPage" title="Trang cuối">
                            <img alt="" class="lastImgEnable" src="/Content/themes/admin/images/clear.gif" /></a></li>
                    }
                    else if (currentPage >= totalPage - 2)
                    {
                        <li>Trang @currentPage / @totalPage</li>
                        <li><a class="first nofollow" href="#" idx="1" title="Trang đầu">
                                <img alt="" class="firstImgEnable" src="/Content/themes/admin/images/clear.gif" /></a></li>
                        pageIndex = currentPage - 1;
                        if (currentPage == 1)
                        {
                            pageIndex = totalPage;
                        }
                        <li><a class="prev nofollow" href="#" idx="@pageIndex" title="Trang trước">
                                <img alt="" class="prevImgEnable" src="/Content/themes/admin/images/clear.gif" /></a></li>

                        for (var i = totalPage - 4; i <= totalPage; i++)
                        {
                            style = "";
                            if (i == currentPage)
                            {
                                style = "active";
                            }
                            <li><a class="@style nofollow" href="#" idx="@i"  title="">@i</a></li>
                        }
                        nextpage = currentPage + 1;
                        if (currentPage == totalPage)
                        {
                            nextpage = 1;
                        }
                        <li><a class="next nofollow" href="#" idx="@nextpage" title="Trang tiếp">
                                <img alt="" class="nextImgEnable" src="/Content/themes/admin/images/clear.gif" /></a></li>
                        <li><a class="last nofollow" href="#" idx="@totalPage" title="Trang cuối">
                                <img alt="" class="lastImgEnable" src="/Content/themes/admin/images/clear.gif" /></a></li>
                    }
                }
            }
        </ul>
    </section>
    <section class="clear"></section>
</section>
<!--end .paging-->
